package com.boang.map;

import com.boang.set.Student;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

/*
  @author: 13813
  @date: 2024/11/29 14:59
*/
public class HashMapDemo {
    public static void main(String[] args) {
//        m1();
        HashMap<Student, String> map = new HashMap<>();
        map.put(new Student("zhangsan", 20), "bj");
        map.put(new Student("lisi", 30), "sh");
        map.put(new Student("wangwu", 50), "gz");
        //遍历
        Set<Student> set = map.keySet();
        Iterator<Student> iterator = set.iterator();
        while (iterator.hasNext()) {
            Student key = iterator.next();
            String value = map.get(key);

            System.out.println(key + ":" + value);
        }
    }

    private static void m1() {
        //key 唯一
        HashMap<Student, String> map = new HashMap<>();
        //增
        map.put(new Student("zhangsan", 20), "bj");
        map.put(new Student("zhangsan", 20), "gz");

        //改
        map.put(new Student("zhangsan", 30), "sh");

        //删
        map.remove(new Student("zhangsan", 30));

        //查
        System.out.println(map.get(new Student("zhangsan", 30)));


        System.out.println(map);
    }
}
